import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SmsTemplateVO, SmsTemplateForm, SmsTemplateQuery, SmsChannelVO, formMessage } from '@/api/sms/template/types';

/**
 * 查询邮件模板列表
 * @param query
 * @returns {*}
 */

export const listSmsTemplate = (query?: SmsTemplateQuery): AxiosPromise<SmsTemplateVO[]> => {
  return request({
    url: '/sms/template/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询邮件模板参数详细
 * @param id
 */
export const getSmsTemplateParam = (id: string | number): AxiosPromise<string[]> => {
  return request({
    url: '/sms/template/param/' + id,
    method: 'get'
  });
};

/**
 * 新增邮件模板
 * @param data
 */
export const addSmsTemplate = (data: SmsTemplateForm) => {
  return request({
    url: '/sms/template',
    method: 'post',
    data: data
  });
};

/**
 * 修改邮件模板
 * @param data
 */
export const updateSmsTemplate = (data: SmsTemplateForm) => {
  return request({
    url: '/sms/template',
    method: 'put',
    data: data
  });
};

/**
 * 删除邮件模板
 * @param id
 */
export const delSmsTemplate = (id: string | number | Array<string | number>) => {
  return request({
    url: '/sms/template/' + id,
    method: 'delete'
  });
};

export const changeTemplateStatus = (id: number | string, status: number) => {
  const data = {
    id: id,
    status: parseInt(status.toString())
  };
  console.log(data);
  return request({
    url: '/sms/template/changeStatus',
    method: 'post',
    data: data
  });
};

/**
 * 查询所有邮件渠道
 */
export const listAllSmsChannel = (): AxiosPromise<SmsChannelVO[]> => {
  return request({
    url: '/sms/channel/listAll',
    method: 'get'
  });
};

export const sendMessageRequst = (data: formMessage) => {
  return request({
    url: '/sms/template/send/message',
    method: 'post',
    data: data
  });
};

/**
 * 查询邮件模板详细
 * @param id
 */
export const getSmsTemplate = (id: string | number): AxiosPromise<SmsTemplateVO> => {
  return request({
    url: '/sms/template/' + id,
    method: 'get'
  });
};
